package com.mission.schedule.CommonDialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.mission.schedule.R;
import com.mission.schedule.applcation.App;
import com.mission.schedule.bean.qd606.NoteTitleDetailBean;
import com.mission.schedule.utils.SharedPrefUtil;

import java.util.List;
import java.util.Map;

/**
 * 清单编辑子项对话框
 * Created by liwei on 2017/4/18.
 */

public class NoteEditChildMenuDialog extends Dialog {


    CallBack callBack;

    SharedPrefUtil sharedPrefUtil = null;
    Context context;
    WindowManager windowManager;


    public NoteEditChildMenuDialog(@NonNull final Context context, @StyleRes int themeResId,
                                   final WindowManager windowManager,
                                   final List<NoteTitleDetailBean.ListBean> bean,
                                   int orderid, final String titleId, final int id) {
        super(context, themeResId);
        this.context = context;
        this.windowManager = windowManager;

        setCanceledOnTouchOutside(true);

        View view = LayoutInflater.from(context).inflate(R.layout.dialog_note_edit_child_menu, null);
        setContentView(view);

        TextView last = view.findViewById(R.id.last);
        TextView next = view.findViewById(R.id.next);
        if (orderid == bean.get(0).orderId ){
            last.setTextColor(context.getResources().getColor(R.color.gongkai_txt));
            last.setEnabled(false);
            last.setClickable(false);
        }
        if (orderid == bean.get(bean.size() - 1).orderId){
            next.setTextColor(context.getResources().getColor(R.color.gongkai_txt));
            next.setEnabled(false);
            next.setClickable(false);
        }

        if (orderid == bean.get(0).orderId && orderid == bean.get(bean.size() - 1).orderId){
            last.setTextColor(context.getResources().getColor(R.color.gongkai_txt));
            last.setEnabled(false);
            last.setClickable(false);
            next.setTextColor(context.getResources().getColor(R.color.gongkai_txt));
            next.setEnabled(false);
            next.setClickable(false);
        }


        last.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callBack.last();
                dismiss();
            }
        });

        next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callBack.next();
                dismiss();
            }
        });
        view.findViewById(R.id.copy_content).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callBack.copycontent();
                dismiss();
            }
        });
        view.findViewById(R.id.copy).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callBack.copy();
                dismiss();
            }
        });
        view.findViewById(R.id.settitle).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callBack.settitle();
                dismiss();
            }
        });
        view.findViewById(R.id.copy_note).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callBack.copytoothernote();
                dismiss();
            }
        });
        view.findViewById(R.id.add_daiban).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callBack.adddaiban();
                dismiss();
            }
        });
        view.findViewById(R.id.add_calender).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callBack.add_calender();
                dismiss();
            }
        });
        view.findViewById(R.id.select_color).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                CalenderColorDialog colorDialog = new CalenderColorDialog(context, R.style.dialog_translucent, windowManager, "", 0);
                colorDialog.show();
                colorDialog.setCallBack(new CalenderColorDialog.CallBack() {
                    @Override
                    public void reminderEditTime(String color_position_f, String color_position) {
                        App.getDBcApplication().updateNoteDetailColor(titleId, id, color_position_f, color_position);
                        callBack.updateColor(color_position_f, color_position);
                    }
                });
            }
        });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        params.width = windowManager.getDefaultDisplay().getWidth() - 30;
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        window.setAttributes(params);
    }

    public interface CallBack {
        void copycontent();
        void copy();
        void settitle();
        void last();
        void next();
        void copytoothernote();
        void adddaiban();
        void add_calender();
        void updateColor(String color_position_f, String color_position);
    }

    public CallBack getCallBack() {
        return callBack;
    }

    public void setCallBack(CallBack callBack) {
        this.callBack = callBack;
    }
}
